<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module RubyVM::RJIT - ruby_vm: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-dump_trace_exits">::dump_trace_exits</a>
    <li ><a href="#method-c-exit_traces">::exit_traces</a>
    <li ><a href="#method-c-format_number">::format_number</a>
    <li ><a href="#method-c-print_counters">::print_counters</a>
    <li ><a href="#method-c-print_exit_counts">::print_exit_counts</a>
    <li ><a href="#method-c-print_stats">::print_stats</a>
    <li ><a href="#method-c-runtime_stats">::runtime_stats</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-RubyVM::RJIT">
    <h1 id="module-RubyVM::RJIT" class="module">
      module RubyVM::RJIT
    </h1>

    <section class="description">
    
    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="CFP">CFP
          <dd>
          <dt id="C_ARGS">C_ARGS
          <dd><p>SystemV x64 calling convention</p>
          <dt id="C_RET">C_RET
          <dd>
          <dt id="CantCompile">CantCompile
          <dd>
          <dt id="Default">Default
          <dd>
          <dt id="EC">EC
          <dd><p>Callee-saved registers TODO: support using r12/r13 here</p>
          <dt id="EndBlock">EndBlock
          <dd>
          <dt id="GC_REFS">GC_REFS
          <dd><p>Mark objects in this Array during GC</p>
          <dt id="KeepCompiling">KeepCompiling
          <dd><p>Compilation status</p>
          <dt id="MAX_LOCAL_TYPES">MAX_LOCAL_TYPES
          <dd><p>Maximum number of local variable types we keep track of</p>
          <dt id="MAX_TEMP_TYPES">MAX_TEMP_TYPES
          <dd><p>Maximum number of temp value types we keep track of</p>
          <dt id="MAX_VERSIONS">MAX_VERSIONS
          <dd><p>Maximum number of versions per block 1 means always create generic versions</p>
          <dt id="MapToLocal">MapToLocal
          <dd>
          <dt id="MapToSelf">MapToSelf
          <dd>
          <dt id="MapToStack">MapToStack
          <dd><p>Potential mapping of a value on the temporary stack to self, a local variable, or constant so that we can track its type</p>
          <dt id="Next0">Next0
          <dd><p>Branch shapes</p>
          <dt id="Next1">Next1
          <dd>
          <dt id="Qfalse">Qfalse
          <dd>
          <dt id="Qnil">Qnil
          <dd>
          <dt id="Qtrue">Qtrue
          <dd><p>Ruby constants</p>
          <dt id="Qundef">Qundef
          <dd>
          <dt id="QwordPtr">QwordPtr
          <dd><p>64-bit memory access</p>
          <dt id="SP">SP
          <dd>
          <dt id="SelfOpnd">SelfOpnd
          <dd><p>Operand to a YARV bytecode instruction</p>
          <dt id="StackOpnd">StackOpnd
          <dd>
          <dt id="Type">Type
          <dd><p>Represent the type of a value (local/stack/self) in <a href="RJIT.html"><code>RJIT</code></a></p>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-runtime_stats" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">runtime_stats</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="runtime_stats-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 3</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">runtime_stats</span>
  <span class="ruby-identifier">stats</span> = {}

  <span class="ruby-comment"># Insn exits</span>
  <span class="ruby-constant">INSNS</span>.<span class="ruby-identifier">each_value</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">insn</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">exits</span> = <span class="ruby-constant">C</span>.<span class="ruby-identifier">rjit_insn_exits</span>[<span class="ruby-identifier">insn</span>.<span class="ruby-identifier">bin</span>]
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">exits</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
      <span class="ruby-identifier">stats</span>[<span class="ruby-value">:&quot;exit_#{insn.name}&quot;</span>] = <span class="ruby-identifier">exits</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Runtime stats</span>
  <span class="ruby-constant">C</span>.<span class="ruby-identifier">rb_rjit_runtime_counters</span>.<span class="ruby-identifier">members</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">member</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">stats</span>[<span class="ruby-identifier">member</span>] = <span class="ruby-constant">C</span>.<span class="ruby-identifier">rb_rjit_counters</span>.<span class="ruby-identifier">public_send</span>(<span class="ruby-identifier">member</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Other stats are calculated here</span>
  <span class="ruby-identifier">stats</span>[<span class="ruby-value">:side_exit_count</span>] = <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">_count</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&#39;exit_&#39;</span>) }.<span class="ruby-identifier">sum</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:last</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">stats</span>[<span class="ruby-value">:vm_insns_count</span>] <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
    <span class="ruby-identifier">retired_in_rjit</span> = <span class="ruby-identifier">stats</span>[<span class="ruby-value">:rjit_insns_count</span>] <span class="ruby-operator">-</span> <span class="ruby-identifier">stats</span>[<span class="ruby-value">:side_exit_count</span>]
    <span class="ruby-identifier">stats</span>[<span class="ruby-value">:total_insns_count</span>] = <span class="ruby-identifier">retired_in_rjit</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">stats</span>[<span class="ruby-value">:vm_insns_count</span>]
    <span class="ruby-identifier">stats</span>[<span class="ruby-value">:ratio_in_rjit</span>] = <span class="ruby-value">100.0</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">retired_in_rjit</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">stats</span>[<span class="ruby-value">:total_insns_count</span>]
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:vm_insns_count</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">stats</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Class Methods</h3>
                </header>

                  <div id="method-c-dump_trace_exits" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">dump_trace_exits</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>–yjit-trace-exits at_exit</p>

                              <div class="method-source-code" id="dump_trace_exits-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 107</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dump_trace_exits</span>
  <span class="ruby-identifier">filename</span> = <span class="ruby-node">&quot;#{Dir.pwd}/rjit_exit_locations.dump&quot;</span>
  <span class="ruby-constant">File</span>.<span class="ruby-identifier">binwrite</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">exit_traces</span>))
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-node">&quot;RJIT exit locations dumped to:\n#{filename}&quot;</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-exit_traces" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">exit_traces</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Convert rb_rjit_raw_samples and rb_rjit_line_samples into a StackProf format.</p>

                              <div class="method-source-code" id="exit_traces-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 114</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">exit_traces</span>
  <span class="ruby-identifier">results</span> = <span class="ruby-constant">C</span>.<span class="ruby-identifier">rjit_exit_traces</span>
  <span class="ruby-identifier">raw_samples</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:raw</span>].<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">line_samples</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:lines</span>].<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">frames</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:frames</span>].<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">samples_count</span> = <span class="ruby-value">0</span>

  <span class="ruby-comment"># Loop through the instructions and set the frame hash with the data.</span>
  <span class="ruby-comment"># We use nonexistent.def for the file name, otherwise insns.def will be displayed</span>
  <span class="ruby-comment"># and that information isn&#39;t useful in this context.</span>
  <span class="ruby-constant">RubyVM</span><span class="ruby-operator">::</span><span class="ruby-constant">INSTRUCTION_NAMES</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">frame_id</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">frame_hash</span> = { <span class="ruby-value">samples:</span> <span class="ruby-value">0</span>, <span class="ruby-value">total_samples:</span> <span class="ruby-value">0</span>, <span class="ruby-value">edges:</span> {}, <span class="ruby-value">name:</span> <span class="ruby-identifier">name</span>, <span class="ruby-value">file:</span> <span class="ruby-string">&quot;nonexistent.def&quot;</span>, <span class="ruby-value">line:</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">lines:</span> {} }
    <span class="ruby-identifier">results</span>[<span class="ruby-value">:frames</span>][<span class="ruby-identifier">frame_id</span>] = <span class="ruby-identifier">frame_hash</span>
    <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">frame_id</span>] = <span class="ruby-identifier">frame_hash</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Loop through the raw_samples and build the hashes for StackProf.</span>
  <span class="ruby-comment"># The loop is based off an example in the StackProf documentation and therefore</span>
  <span class="ruby-comment"># this functionality can only work with that library.</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Raw Samples:</span>
  <span class="ruby-comment"># [ length, frame1, frame2, frameN, ..., instruction, count</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># Line Samples</span>
  <span class="ruby-comment"># [ length, line_1, line_2, line_n, ..., dummy value, count</span>
  <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
  <span class="ruby-keyword">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">raw_samples</span>.<span class="ruby-identifier">length</span>
    <span class="ruby-identifier">stack_length</span> = <span class="ruby-identifier">raw_samples</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-comment"># consume the stack length</span>

    <span class="ruby-identifier">prev_frame_id</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">stack_length</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">idx</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">idx</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">i</span>
      <span class="ruby-identifier">frame_id</span> = <span class="ruby-identifier">raw_samples</span>[<span class="ruby-identifier">idx</span>]

      <span class="ruby-keyword">if</span> <span class="ruby-identifier">prev_frame_id</span>
        <span class="ruby-identifier">prev_frame</span> = <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">prev_frame_id</span>]
        <span class="ruby-identifier">prev_frame</span>[<span class="ruby-value">:edges</span>][<span class="ruby-identifier">frame_id</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
        <span class="ruby-identifier">prev_frame</span>[<span class="ruby-value">:edges</span>][<span class="ruby-identifier">frame_id</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-identifier">frame_info</span> = <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">frame_id</span>]
      <span class="ruby-identifier">frame_info</span>[<span class="ruby-value">:total_samples</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>

      <span class="ruby-identifier">frame_info</span>[<span class="ruby-value">:lines</span>][<span class="ruby-identifier">line_samples</span>[<span class="ruby-identifier">idx</span>]] <span class="ruby-operator">||=</span> [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>]
      <span class="ruby-identifier">frame_info</span>[<span class="ruby-value">:lines</span>][<span class="ruby-identifier">line_samples</span>[<span class="ruby-identifier">idx</span>]][<span class="ruby-value">0</span>] <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>

      <span class="ruby-identifier">prev_frame_id</span> = <span class="ruby-identifier">frame_id</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">stack_length</span> <span class="ruby-comment"># consume the stack</span>

    <span class="ruby-identifier">top_frame_id</span> = <span class="ruby-identifier">prev_frame_id</span>
    <span class="ruby-identifier">top_frame_line</span> = <span class="ruby-value">1</span>

    <span class="ruby-identifier">sample_count</span> = <span class="ruby-identifier">raw_samples</span>[<span class="ruby-identifier">i</span>]

    <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">top_frame_id</span>][<span class="ruby-value">:samples</span>] <span class="ruby-operator">+=</span> <span class="ruby-identifier">sample_count</span>
    <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">top_frame_id</span>][<span class="ruby-value">:lines</span>] <span class="ruby-operator">||=</span> {}
    <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">top_frame_id</span>][<span class="ruby-value">:lines</span>][<span class="ruby-identifier">top_frame_line</span>] <span class="ruby-operator">||=</span> [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>]
    <span class="ruby-identifier">frames</span>[<span class="ruby-identifier">top_frame_id</span>][<span class="ruby-value">:lines</span>][<span class="ruby-identifier">top_frame_line</span>][<span class="ruby-value">1</span>] <span class="ruby-operator">+=</span> <span class="ruby-identifier">sample_count</span>

    <span class="ruby-identifier">samples_count</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">sample_count</span>
    <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">results</span>[<span class="ruby-value">:samples</span>] = <span class="ruby-identifier">samples_count</span>
  <span class="ruby-comment"># Set missed_samples and gc_samples to 0 as their values</span>
  <span class="ruby-comment"># don&#39;t matter to us in this context.</span>
  <span class="ruby-identifier">results</span>[<span class="ruby-value">:missed_samples</span>] = <span class="ruby-value">0</span>
  <span class="ruby-identifier">results</span>[<span class="ruby-value">:gc_samples</span>] = <span class="ruby-value">0</span>
  <span class="ruby-identifier">results</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-format_number" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">format_number</span><span
                                class="method-args">(pad, number)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Format large numbers with comma separators for readability</p>

                              <div class="method-source-code" id="format_number-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 99</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">format_number</span>(<span class="ruby-identifier">pad</span>, <span class="ruby-identifier">number</span>)
  <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">decimal</span> = <span class="ruby-identifier">number</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39;.&#39;</span>)
  <span class="ruby-identifier">d_groups</span> = <span class="ruby-identifier">integer</span>.<span class="ruby-identifier">chars</span>.<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">each_slice</span>(<span class="ruby-value">3</span>)
  <span class="ruby-identifier">with_commas</span> = <span class="ruby-identifier">d_groups</span>.<span class="ruby-identifier">map</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:join</span>).<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39;,&#39;</span>).<span class="ruby-identifier">reverse</span>
  [<span class="ruby-identifier">with_commas</span>, <span class="ruby-identifier">decimal</span>].<span class="ruby-identifier">compact</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39;.&#39;</span>).<span class="ruby-identifier">rjust</span>(<span class="ruby-identifier">pad</span>, <span class="ruby-string">&#39; &#39;</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-print_counters" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">print_counters</span><span
                                class="method-args">(stats, prefix:, prompt:)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="print_counters-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span>, <span class="ruby-value">prompt:</span>)
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-node">&quot;#{prompt}: &quot;</span>)
  <span class="ruby-identifier">counters</span> = <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">filter</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">_</span><span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-identifier">prefix</span>) }
  <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">filter!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">_</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> }
  <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">transform_keys!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">delete_prefix</span>(<span class="ruby-identifier">prefix</span>) }

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-string">&quot;    (all relevant counters are zero)&quot;</span>)
    <span class="ruby-keyword">return</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">counters</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">to_a</span>
  <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">sort_by!</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">_</span>, <span class="ruby-identifier">counter_value</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">counter_value</span> }
  <span class="ruby-identifier">longest_name_length</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">max_by</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">_</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">length</span> }.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">length</span>
  <span class="ruby-identifier">total</span> = <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">sum</span> { <span class="ruby-operator">|</span>(<span class="ruby-identifier">_</span>, <span class="ruby-identifier">counter_value</span>)<span class="ruby-operator">|</span> <span class="ruby-identifier">counter_value</span> }

  <span class="ruby-identifier">counters</span>.<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)<span class="ruby-operator">|</span>
    <span class="ruby-identifier">percentage</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">fdiv</span>(<span class="ruby-identifier">total</span>) <span class="ruby-operator">*</span> <span class="ruby-value">100</span>
    <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">printf</span>(<span class="ruby-string">&quot;    %*s %s (%4.1f%%)\n&quot;</span>, <span class="ruby-identifier">longest_name_length</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">format_number</span>(<span class="ruby-value">10</span>, <span class="ruby-identifier">value</span>), <span class="ruby-identifier">percentage</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-print_exit_counts" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">print_exit_counts</span><span
                                class="method-args">(stats, how_many: 20, padding: 2)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="print_exit_counts-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 82</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_exit_counts</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">how_many:</span> <span class="ruby-value">20</span>, <span class="ruby-value">padding:</span> <span class="ruby-value">2</span>)
  <span class="ruby-identifier">exits</span> = <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">filter_map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">count</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">delete_prefix</span>(<span class="ruby-string">&#39;exit_&#39;</span>), <span class="ruby-identifier">count</span>] <span class="ruby-keyword">if</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&#39;exit_&#39;</span>) }.<span class="ruby-identifier">to_h</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">exits</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-identifier">top_exits</span> = <span class="ruby-identifier">exits</span>.<span class="ruby-identifier">sort_by</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">_name</span>, <span class="ruby-identifier">count</span><span class="ruby-operator">|</span> <span class="ruby-operator">-</span><span class="ruby-identifier">count</span> }.<span class="ruby-identifier">first</span>(<span class="ruby-identifier">how_many</span>).<span class="ruby-identifier">to_h</span>
  <span class="ruby-identifier">total_exits</span> = <span class="ruby-identifier">exits</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">sum</span>
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Top-#{top_exits.size} most frequent exit ops (#{format(&quot;%.1f&quot;, 100.0 * top_exits.values.sum / total_exits)}% of exits):&quot;</span>

  <span class="ruby-identifier">name_width</span>  = <span class="ruby-identifier">top_exits</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">_count</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">length</span> }.<span class="ruby-identifier">max</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">padding</span>
  <span class="ruby-identifier">count_width</span> = <span class="ruby-identifier">top_exits</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">_name</span>, <span class="ruby-identifier">count</span><span class="ruby-operator">|</span> <span class="ruby-identifier">format_number</span>(<span class="ruby-value">10</span>, <span class="ruby-identifier">count</span>).<span class="ruby-identifier">length</span> }.<span class="ruby-identifier">max</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">padding</span>
  <span class="ruby-identifier">top_exits</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">count</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">ratio</span> = <span class="ruby-value">100.0</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">total_exits</span>
    <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{format(&quot;%#{name_width}s&quot;, name)}: #{format_number(count_width, count)} (#{format(&#39;%4.1f&#39;, ratio)}%)&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-print_stats" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">print_stats</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>–yjit-stats at_exit</p>

                              <div class="method-source-code" id="print_stats-source">
            <pre><span class="ruby-comment"># File ruby_vm/rjit/stats.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">print_stats</span>
  <span class="ruby-identifier">stats</span> = <span class="ruby-identifier">runtime_stats</span>
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-string">&quot;***RJIT: Printing RJIT statistics on exit***&quot;</span>)

  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;send_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;method call exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;invokeblock_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;invokeblock exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;invokesuper_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;invokesuper exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;getblockpp_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;getblockparamproxy exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;getivar_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;getinstancevariable exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;setivar_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;setinstancevariable exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;optaref_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;opt_aref exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;optgetconst_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;opt_getconstant_path exit reasons&#39;</span>)
  <span class="ruby-identifier">print_counters</span>(<span class="ruby-identifier">stats</span>, <span class="ruby-value">prefix:</span> <span class="ruby-string">&#39;expandarray_&#39;</span>, <span class="ruby-value">prompt:</span> <span class="ruby-string">&#39;expandarray exit reasons&#39;</span>)

  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;compiled_block_count:  #{format_number(13, stats[:compiled_block_count])}&quot;</span>
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;side_exit_count:       #{format_number(13, stats[:side_exit_count])}&quot;</span>
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;total_insns_count:     #{format_number(13, stats[:total_insns_count])}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:total_insns_count</span>)
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;vm_insns_count:        #{format_number(13, stats[:vm_insns_count])}&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:vm_insns_count</span>)
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;rjit_insns_count:      #{format_number(13, stats[:rjit_insns_count])}&quot;</span>
  <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;ratio_in_rjit:         #{format(&#39;%12.1f&#39;, stats[:ratio_in_rjit])}%&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">stats</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-value">:ratio_in_rjit</span>)

  <span class="ruby-identifier">print_exit_counts</span>(<span class="ruby-identifier">stats</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

